
<script type="text/javascript">
    $(function(){
    
        $('#categories').dblclick(function(ev){
            
            $('#categoriesSelected')
            .append($('<option>', { value : this.value })
            .text($(this).children('option:selected').text())); 
            if(off)
                return;
            var url = document.URL.toString()
            .setParam("categoryId",this.value)
            .setParam("add",1);
            
            ajx({
                url:  url
            })
            
        });
        
        $('#submitAndStay,#submit').attr('multiple','multiple').click(function(ev){
            $('#categoriesSelected option').attr('selected', 'selected');
          
        });
        
        $('#categoriesSelected').attr('name','categoriesSelected[]');
    
        $('#categoriesSelected').dblclick(function(ev){
            
            var selected = $(this).children('option:selected');
            var opt = $(this).children('option:selected[value="'+selected.val()+'"]');
            var url = document.URL.toString()
            .setParam("categoryId",selected.val())
            .setParam("delete",1);
            
            ajx({
                url:  url
            })
            
            opt.remove();
            
        });
        
        $('#btnGlowna').click(function(ev){
            
            $('#idGlowna').val($('#categoriesSelected').children('option:selected').val());
            $('#idGlowna-label label').text($('#categoriesSelected').children('option:selected').text());
        });
        
        $('#categoriesSelected-element').after( $('<div />',{'class': 'cls'}));
    
    });
</script>